package com.csnf.controller;

import com.csnf.dto.ResponseObject;
import com.csnf.entity.Admin;
import com.csnf.entity.MerchantAccount;
import com.csnf.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class LoginController {
    @Autowired
    private LoginService loginService;
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public ResponseObject login(@RequestBody Admin admin){
        int loginFlag = loginService.login(admin);
        if(loginFlag==1){
            return ResponseObject.success("success");
        }else{
            return ResponseObject.error("error");
        }
    }

    @RequestMapping(value = "/merchantLogin",method = RequestMethod.POST)
    public ResponseObject merchantLogin(@RequestBody MerchantAccount merchantAccount){
        List<MerchantAccount> merchantAccounts= loginService.merchantlogin(merchantAccount);
        if (merchantAccounts.size()>0){
            return ResponseObject.success("success",merchantAccounts);
        }else {
            return ResponseObject.error("error");
        }

    }
}
